package com.weiwei.diancan.activity;

import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.weiwei.diancan.cache.CacheConfig;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by BMW on 2016/11/4.
 */
public class MyReeceivers extends BroadcastReceiver {
    private NotificationManager nm;
    private String TAG = "weiwei";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (null == nm) {
            nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        }

        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            Log.e(TAG, "JPush用户注册成功");

        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            Log.e(TAG, "接受到推送下来的自定义消息");

        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
            Log.e(TAG, "接受到推送下来的通知");

            //TODO:再次处理消息
            CacheConfig.getInst().putFlag("weiwei",context);
        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            Log.e(TAG, "用户点击打开了通知");


        } else {
            Log.e(TAG, "Unhandled intent - " + intent.getAction());
        }
    }
}
